package offer.easy;

public class PukeContinues {

    public static boolean isContinues(int[] array) {
        int len = array.length;
        if (len < 5) {
            return false;
        }
        int temp = 0;
        int counts = 0;
        for (int i = 0; i < len-1; i++) {
            for(int j = 0; j < len-i-1; j++) {
                if (array[j] > array[j+1]) {
                    temp = array[j+1];
                    array[j+1] = array[j];
                    array[j] = temp;
                }
            }
        }
        for (int i = 0; i < len-1; i++) {
            if (array[i]==0) {
                counts++;
            } else if (array[i]==array[i+1]) {
                return false;
            }
        }
        if ((array[len-1]-array[counts])>4) {
            return false;
        }
        return true;
    }

    public static boolean isContinues2(int[] array) {
        int max = 0;
        int min = 15;
        int counts = 0;
        for (int i : array) {
            if (i==0) {
                counts++;
                continue;
            }
            max = Math.max(max,i);
            min = Math.min(min,i);
        }
        return (max-min)<5 && (max-min)>3-counts;
    }

    public static void main(String[] args) {
        int[] array = {1,3,2,6,4};

        System.out.println(isContinues(array));
    }
}
